<?php
function db_connect() {

$link = mysql_connect('66.118.188.130', 'kootenay', 'nonsense');
 if (!$link) {
  die ('Not connected : ' . mysql_error());
 }
 $db_selected = mysql_select_db('kootenay', $link);

 if (!$db_selected) {
  die ('Can\'t use foo : ' . mysql_error());
 }
 
}


 ////////////////////////////
// FUNCTION FOR db CLOSE  //

function db_close() {
 mysql_close();
}

function dateformat($date, $end_date, $format = 1) { 

	preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/',$date,$date_parts);
	preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/',$end_date,$end_date_parts);
	$months = array ('1' => 'January' , 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); 		    //print_r ($months);
	$monthnum = ltrim ($date_parts[2], "0"); //echo "--------" . $monthnum;
	$day = ltrim ($date_parts[3], "0"); //echo "--------" . $monthnum;
	$month = $months[$monthnum];
	$end_monthnum = ltrim ($end_date_parts[2], "0"); //echo "--------" . $monthnum;
	$end_day = ltrim ($end_date_parts[3], "0"); //echo "--------" . $monthnum;
	$end_month = $months[$end_monthnum];
	
	if ($format == 1)
	{
		if ($end_date) 
			{
				if ($end_monthnum != $monthnum)
				{
				$date = $month . " $day-$end_month $end_day, $date_parts[1]";  /// Jan 23 - Feb 2, 2008
				} else {
				$date = $month . " $day-$end_day, $date_parts[1]"; /// Jan 23 - 25, 2008
				}
			} else {
				$date = $month . " $day, $date_parts[1]"; /// Jan 23, 2008
				
			}
	}
	
	if ($format == 2)
	{
		$date = $monthnum . "/$day/" . $date_parts[1]; /// 12/24/08
	}
	
	if ($format == 3)
	{
		$date = $monthnum . "/$day"; /// 12/24
	}
	
	return $date;
} 
 
function padWithZeros($s, $n) {
  return sprintf("%0" . $n . "d", $s);
}

function timeFormat($time, $format=1) {

	$hour = substr($time,0,2);
	$minute = substr($time,3,2);

	if ($format == 1) {
		if ($hour >= 12) {
			if ($hour >= 24) {
				if ($hour > 24){ 
					  $hour = ($hour-24);
					} else {
					  $hour = ($hour-12);  
					}
				$ampm = " am";
			} else { 
				if ($hour > 12) $hour = ($hour-12); 
				$ampm = " pm";
			} 
		} else {
			$ampm = " am";
		}
	   
	}
	
	return $hour.":".$minute." $ampm";
}  
	


?>
